package com.rf.richfitwheel.utils;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@ApiModel(value = "分页对象", description = "")
@Data
@NoArgsConstructor
public class PageJson implements Serializable {

    private static final long serialVersionUID = 5909984859866687892L;
    //当前页
    @ApiModelProperty(dataType = "int",  name = "pageNum", value = "当前页")
    private int pageNum = 1;
    //每页条数
    @ApiModelProperty(dataType = "int",  name = "pageSize", value = "每页条数")
    private int pageSize = 10;
    //总页数
    @ApiModelProperty(dataType = "int",  name = "pageTotal", value = "总页数")
    private int pageTotal;
    //总条数
    @ApiModelProperty(dataType = "int",  name = "total", value = "总条数")
    private int total;
    //列表数据
    @ApiModelProperty(dataType = "int",  name = "list", value = "数据集")
    private List<?> list;

    public PageJson(int pageNum, int pageSize, int pageTotal, int total, List<?> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.pageTotal = pageTotal;
        this.total = total;
        this.list = list;
    }

    public PageJson(long pageNum, long pageSize, long pageTotal, long total, List<?> list) {
        this.pageNum = (int) pageNum;
        this.pageSize = (int) pageSize;
        this.pageTotal = (int) pageTotal;
        this.total = (int) total;
        this.list = list;
    }

    public static PageJson of(Page page) {
        return new PageJson(page.getCurrent(), page.getSize(), page.getPages(), page.getTotal(), page.getRecords());
//        this.current = (int) page.getCurrent();
//        this.size = (int) page.getPages();
//        this.pageSize = (int) page.getSize();
//        this.total = (int) page.getTotal();
//        this.list = page.getRecords();
    }
}
